#include"comm.hpp"
#include<cstdlib>
int main()
{
  std::cerr<<"进入cgi"<<std::endl;
  std::string query_string;
  //拿到字符串
  GetQueryString(query_string);
  std::cerr<<"获得的字符串是"<<query_string<<std::endl;
  //a=100&b=200
  //切割字符串
  
  std::string first;
  std::string second;
  std::string third;
  std::string last;
  CutString(query_string,"&",first,last);
  CutString(last,"&",second,third);
  std::cerr<<first<<std::endl;
  std::cerr<<second<<std::endl;
  std::string tmp;
  std::string a;
  std::string c;
  std::string b;
  CutString(first,"=",tmp,a);
  CutString(second,"=",tmp,c);
  CutString(third,"=",tmp,b);
  std::cerr<<a<<std::endl;
  std::cerr<<c<<std::endl;
  if(c.size()!=1)
  {
    std::cout<<"输入符号位数错误"<<std::endl;
          std::cout << "<html>";
          std::cout << "<head><meta charset=\"utf-8\"></head>";
          std::cout << "<body><h1>请输入一个上面支持的字符</h1><br></body>";
          return 0;
  }
  switch(*(char*)c.c_str())
  {
    case '+':
          std::cout << "a+b="<<(long long)(atol(a.c_str())+atol(b.c_str()));
     break; 
    case '-':
          std::cout << "a-b="<<(long long)(atol(a.c_str())-atol(b.c_str()));
    break;
    case '*':
          std::cout << "a*b="<<(long long)(atol(a.c_str())*atol(b.c_str()));
    break;
    case '/':
          std::cout << "a/b="<<(long long)(atol(a.c_str())/atol(b.c_str()));
    break;
    default:
          std::cout << "<html>";
          std::cout << "<head><meta charset=\"utf-8\"></head>";
          std::cout << "<body><h1>符号输入错误</h1><br>";
          std::cout<<"<a href=\"http://101.35.110.87:8081/mysql_cgilog\">返回计算</a></body></html>";
    break;

  }


  //向标准输出1写入
  return 0;
}
